package com.vvlive.caibao.smartcity.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.bean.IndexFuncationListBean;

import java.util.List;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by lenovo on 2015/6/29.
 * 添加功能的
 */
public class AddFunctionAdapter extends BaseAdapter {
    Context mContext;
    List<IndexFuncationListBean> mList;
    boolean[] poi;
    public AddFunctionAdapter(Context context, List<IndexFuncationListBean> mList) {
        mContext = context;
        this.mList = mList;
        poi = new boolean[mList.size()];
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.index_add_ft_lv_item, null);
            vh = new ViewHolder();
            vh.mImageView = (ImageView) convertView.findViewById(R.id.add_item_icn);
            vh.mTextView = (TextView) convertView.findViewById(R.id.add_item_text);
            vh.mCheckBox = (CheckBox) convertView.findViewById(R.id.add_item_checkBox);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.mImageView.setImageResource(mList.get(position).getIcn());
        vh.mTextView.setText(mList.get(position).getText());
        vh.mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                poi[position] = isChecked;
            }
        });

        if(poi[position]){
            convertView.setBackgroundColor(Color.rgb(185, 211, 238));
        }else{
            convertView.setBackgroundColor(Color.WHITE);
        }
        return convertView;
    }

    class ViewHolder {
        ImageView mImageView;
        TextView mTextView;
        CheckBox mCheckBox;
    }
}
